import Vue from 'vue'
import VueRouter from 'vue-router'
// import course from '../views/course/course.vue'
import zhuanye from '../views/course/zhuanye.vue'
import home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'Home',
    components: {
      default: home,
      zhuanye,
      // course,
    },
    meta: {
      name: 'Home'
    }
  },

  {
    path: '/course',
    name: 'course',
    component: () => import('../views/course/course.vue'),
  },
  {
    path: '/course/detail',
    name: 'courseDetail',
    component: () => import('../views/course/details.vue'),
  },

  {
    path: '/search',
    name: 'search',
    component: () => import('../views/List/Search.vue'),
  },
  {
    path: '/list',
    name: 'list',
    component: () => import('../views/List.vue'),
    meta: {
      name: 'List'
    }
  },
  {
    path: '/study',
    name: 'study',
    component: () => import('../views/study.vue'),
    meta: {
      name: 'Cart',
      islogin: true
    }
  },
  {
    path: '/User',
    name: 'user',
    component: () => import('../views/User.vue'),
    meta: {
      name: 'User'
    }
  },
  {
    path: '/article',
    name: 'article',
    component: () => import('../views/course/article.vue'),
  },
  {
    path: '/dingdan',
    name: 'dingdan',
    component: () => import('../views/course/dingdan.vue'),
  },
  {
    path: '/learner',
    name: 'learner',
    component: () => import('../views/course/xuexi.vue'),
  },
  {
    path: '/ppt',
    name: 'ppt',
    component: () => import('../views/List/ppt.vue'),
  },
  {
    path: '/balance',
    name: 'Balance',
    component: () => import('../views/account/Balance.vue'),
  },
  {
    path: '/recharge',
    name: 'Recharge',
    component: () => import('../views/account/Recharge.vue'),
  },
  {
    path: '/set',
    name: 'Set',
    component: () => import('../views/account/Set.vue'),
  },
  {
    path: '/logout',
    name: 'Logout',
    component: () => import('../views/login/Logout.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/Login.vue'),
  },
  {
    path: '/number',
    name: 'Number',
    component: () => import('../views/login/Number.vue'),
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/login/Register.vue'),
  }, {
    path: '/live',
    name: 'Live',
    component: () => import('../views/study/Live.vue'),
  },
  {
    path: '/inventory',
    name: 'inventory',
    component: () => import('../views/study/inventory.vue'),
  },
  {
    path: '/interest',
    name: 'Interest',
    component: () => import('../views/account/Interest.vue'),
  },
  {
    path: '/person',
    name: 'Person',
    component: () => import('../views/account/Person.vue'),
  },
]

const router = new VueRouter({
  routes,
  mode: 'history',
})


router.beforeEach(function (to, from, next) {
  if (to.meta.islogin) {
    if (localStorage.getItem("account")) {
      next()
    } else {
      next('/login')
    }
  }
  next()

})

export default router